import { request } from "../util/request.js";

export default {
    //电影信息列表
    get: async () => {
        return await request({
            type: "GET",
            url: "/api/movies/all",
        });
    },
    //把获取到的相对应的值存储在本地
    setStorage: movies =>
        (localStorage["updade-movies"] = JSON.stringify(movies)),
    //获取本地存储的值
    getStorage: () => JSON.parse(localStorage["updade-movies"]),

    //修改电影信息
    update: async movies => {
        //发起数据修改请求
        return await request({
            type: "PUT",
            url: `/api/movies/${movies._id}`,
            data: movies
        })
    },
    //获取某一条的电影相关信息
    getOne: async _id => {
        return await request({
            type: "GET",
            url: `/api/movies/${_id}`
        })
    },
    //删除某一条电影以及相关信息
    removeMovie: async ({ _id }) => {
        return await request({
            type: "DELETE",
            url: `/api/movies/${_id}`,
        })
    },
    //删除电影相关图片
    removeImg: async ({ _id, url }) => {
        return await request({
            type: "DELETE",
            url: `/resource/movies/${_id}`,
            data: { url }
        })
    },
    // 添加电影信息
    add: async movies => {
        return await request({
            type: "POST",
            url: "/api/movies/add",
            data: movies
        })
    },
    // 获取所有电影
    getAll: async () => {
        return await request({
            type: "get",
            url: "/api/movies/all",
        })
    }
}